package com.zoe.onelink.logging.trace.sql.p6spy;

import com.p6spy.engine.logging.Category;
import com.p6spy.engine.spy.appender.Slf4JLogger;
import com.zoe.onelink.logging.trace.sql.SqlExecuteContextHolder;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-03-08
 */
@Slf4j
public class OnelinkSlf4jLogger extends Slf4JLogger {


    /**
     * SQL最大长度限制 (1MB)
     */
    public static final int MAX_SQL_LENGTH = 1024 * 1024;

    @Override
    public void logException(Exception e) {
        super.logException(e);
    }

    @Override
    public void logText(String text) {
        super.logText(text);
    }

    @Override
    public void logSQL(int connectionId, String now, long elapsed, Category category, String prepared, String sql, String url) {
        if (sql.length() <= MAX_SQL_LENGTH) {
            SqlExecuteContextHolder.set(SqlExecuteContextHolder.SQL, sql);
        }
    }

    @Override
    public boolean isCategoryEnabled(Category category) {
        return super.isCategoryEnabled(category);
    }


}
